package com.sjg.sys.controller;

import com.sjg.sys.entity.*;
import com.sjg.sys.service.SysDictionaryService;
import com.sjg.sys.service.SysUserService;
import com.sjg.sys.utils.CommUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by fuqingjian on 2017/4/30.
 */
@Controller
@RequestMapping("dictionary")
public class SysDictionaryController {
    @Resource
    private SysDictionaryService sysDictionaryService;
    @RequestMapping("index")
    public String index(){
        return "dictionary";
    }
    @ResponseBody
    @RequestMapping("querySysDicRoots")
    public Map<String,Object> querySysDictionarysRoot(){
        SysDictionary dictionary=new SysDictionary();
        dictionary.setPid(-1L);
        List<SysDictionary> dictionaries=sysDictionaryService.selectDic(dictionary);
        List<SysListRow> listRows=CommUtil.getSysListRows(dictionaries,"value","id");
        Map<String,Object> result=new HashMap<>();
        result.put("rows",listRows);
        return result;
    }
    @ResponseBody
    @RequestMapping("querySysDictionarys")
    public Map<String,Object> querySysDictionarys(){
        SysDictionary dictionary=new SysDictionary();
//        dictionary.setPid(-1L);
        List<SysDictionary> dictionaries=sysDictionaryService.selectDic(dictionary);
        List<SysPageCol> cols=new ArrayList<>();
        SysPageCol col0=new SysPageCol();
        col0.setName("编码");
        col0.setField("code");
        SysPageCol col1=new SysPageCol();
        col1.setName("值");
        col1.setField("value");
        cols.add(col0);
        cols.add(col1);
        Map<String,Object> result=new HashMap<>();
        result.put("cols",cols);
        result.put("rows",dictionaries);
        return result;
    }

}
